#pragma once

class material
{
public:
	material();
	material(const std::string &name);
	~material();

	void clear();

	void set_name(const std::string &name);

	void set_ambient_map(texture_ptr ambient);
	void set_diffuse_map(texture_ptr diffuse);
	void set_specular_map(texture_ptr specular);

	void set_ambbient_colour(const vector4 &colour);
	void set_diffuse_colour(const vector4 &colour);
	void set_specular_colour(const vector4 &colour);

	void set_doublesided(bool enabled);
	void set_transparency(bool transparent);

	void add_submaterial(const material &submtl);

	std::string get_name() const;

	texture_ptr get_ambient() const;
	texture_ptr get_diffuse() const;
	texture_ptr get_specular() const;

	vector4 get_ambient_colour() const;
	vector4 get_diffuse_colour() const;
	vector4 get_specular_colour() const;

	bool is_doublesided() const;

	bool has_transparency() const;

	size_t get_num_submaterials() const;
	material get_submaterial(size_t id) const;

private:
	typedef std::vector<material> submaterial_vec;

	submaterial_vec	m_submaterials;

	std::string		m_name;

	texture_ptr		m_ambient_map;
	texture_ptr		m_diffuse_map;
	texture_ptr		m_specular_map;

	bool			m_doublesided;

	bool			m_transparency;

	vector4			m_ambient;
	vector4			m_diffuse;
	vector4			m_specular;
};

inline material::material()
	:	m_transparency(false),
		m_doublesided(false)
{ }

inline material::material(const std::string &name)
	:	m_transparency(false),
		m_doublesided(false),
		m_name(name)
{ }

inline material::~material() { }

inline void material::clear()
{
	m_name.clear();
	m_ambient_map.release();
	m_diffuse_map.release();
	m_specular_map.release();
	m_submaterials.clear();
	m_transparency = false;
}

inline void material::set_name(const std::string &name) { m_name = name; }

inline void material::set_ambient_map(texture_ptr ambient) { m_ambient_map = ambient; }

inline void material::set_diffuse_map(texture_ptr diffuse) { m_diffuse_map = diffuse; }

inline void material::set_specular_map(texture_ptr specular) { m_specular_map = specular; }

inline void  material::set_doublesided(bool enabled) { m_doublesided = enabled; }

inline void  material::set_transparency(bool transparent) { m_transparency = transparent; }

inline void material::add_submaterial(const material &submtl) { m_submaterials.push_back(submtl); }

inline std::string material::get_name() const { return m_name; }

inline texture_ptr material::get_ambient() const { return m_ambient_map; }

inline texture_ptr material::get_diffuse() const { return m_diffuse_map; }

inline texture_ptr material::get_specular() const { return m_specular_map; }

inline size_t material::get_num_submaterials() const { return m_submaterials.size(); }

inline material material::get_submaterial(size_t id) const { return m_submaterials[id]; }

inline bool material::is_doublesided() const { return m_doublesided; }

inline bool material::has_transparency() const { return m_transparency; }

inline void material::set_ambbient_colour(const vector4 &colour) { m_ambient = colour; }

inline void material::set_diffuse_colour(const vector4 &colour) { m_diffuse = colour; }

inline void material::set_specular_colour(const vector4 &colour) { m_specular = colour; }

inline vector4 material::get_ambient_colour() const { return m_ambient; }

inline vector4 material::get_diffuse_colour() const { return m_diffuse; }

inline vector4 material::get_specular_colour() const { return m_specular; }